package cn.wzg.fragmentsample;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class TitleFragment extends Fragment {
    /*接口*/
    public interface OnItemClick{
        /*定义一个获取信息的方法*/
        public void onTitleSelected(int position);
    }

    OnItemClick onItemClick;

    public void setOnItemClick(OnItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }

    public TitleFragment() {
        // Required empty public constructor
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_title, container, false);
        ListView listView=view.findViewById(R.id.lv_title);
        listView.setAdapter(new ArrayAdapter<String>(getContext(),
                android.R.layout.simple_list_item_1,Data.TITLES));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                onItemClick.onTitleSelected(position);
            }
        });
        return view;

    }
}